#ifndef JABSTRACTINTERFACECALLER_H
#define JABSTRACTINTERFACECALLER_H

#include <functional>
#include <QTECore/qteglobal.h>
#include <QVariant>
#include <QObject>

#ifndef QTE_interface_register
# define QTE_interface_register(Type, name, ...) \
	QTE_type_register(Type, name, __VA_ARGS__)
#endif

#ifndef QTE_interface_register_id
# define QTE_interface_register_id(Type, user_id, ...) \
	QTE_type_register(Type, "ClassName_"#user_id, __VA_ARGS__)
#endif

namespace QTE
{

class JAbstractInterfaceCallerPrivate;

class QTECORE_EXPORT JAbstractInterfaceCaller : public QObject
{
	Q_OBJECT

public:
	explicit JAbstractInterfaceCaller(QObject *parent = nullptr);
	virtual ~JAbstractInterfaceCaller() = 0;

public:
	typedef std::function<void(const QVariant&)> CallBack;

public:
	virtual QVariant call() = 0;
	virtual void call(const CallBack &callBack); //default global thread pool
	virtual void call(const QObject *cobj, const CallBack &callBack);

public:
	inline QVariant operator()();
	inline void operator()(const CallBack &callBack);
	inline void operator()(const QObject *cobj, const CallBack &callBack);

public:
	virtual void deleteLater();

protected:
	virtual QVariant analysis(const QVariant &srcData) const;

private:
	JAbstractInterfaceCallerPrivate *d_ptr;
};

inline void JAbstractInterfaceCaller::call(const CallBack &callBack)
{
	call(nullptr, callBack);
}

inline QVariant JAbstractInterfaceCaller::operator()()
{
	return call();
}

inline void JAbstractInterfaceCaller::operator()(const CallBack &callBack)
{
	call(callBack);
}

inline void JAbstractInterfaceCaller::operator()(const QObject *cobj, const CallBack &callBack)
{
	call(cobj, callBack);
}

} //namespace QTE


#endif //JABSTRACTINTERFACECALLER_H
